"""
A fetcher is a callable that accepts an iterable with stock symbols and returns list of tuples
containing symbols and the latest price.
A fetcher usually fetches price from some finance portal hence works only with the stock symbols
that the portal uses.
eg.
>>> print yahoo(["LT.NS", "POWERGRID.NS"])
[('LT.NS', 2549.0), ('POWERGRID.NS', 89.549999999999997)]
>>> print google(["BOM:532693"])
[('BOM:532693', 289.50)]
"""
import urllib

yahoo_updt_url = "http://finance.yahoo.com/d/quotes.csv?s=%s&f=sl1&e=.csv"

def yahooFetcher(symbols):
    if isinstance(symbols, (list, tuple)):
        symbols_joined = "+".join(symbols)
    url = yahoo_updt_url % symbols_joined
    #data = urllib.urlopen(url).readlines()
    #for record in data:
    prices = iter((78, 445.9, 23, 349.02, 67, 92.10, 3.85))
    for sym in symbols:
        #sym, price = record.strip().replace('"','').split(',')
        price = prices.next()
        import time
        time.sleep(1)
        yield (sym, float(price))

yahoo = yahooFetcher

#print yahoo(["LT.NS", "POWERGRID.NS"])
